/*
 * @Author: 米亚流年 miyaliunian@gmail.com
 * @Date: 2023-12-29 22:59:49
 * @LastEditors: 米亚流年 miyaliunian@gmail.com
 * @LastEditTime: 2024-01-04 14:13:50
 * @FilePath: /low-comps/packages/docs/plugins/utils/ts-to-js.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const { transformSync } = require('esbuild')

const tsToJs = (content) => {
  if (!content) {
    return ''
  }
  const beforeTransformContent = content.replace(
    /\n(\s)*\n/g,
    '\n__blankline\n'
  )
  const { code } = transformSync(beforeTransformContent, {
    loader: 'ts',
    minify: false,
    minifyWhitespace: false,
    charset: 'utf8'
  })

  return code.trim().replace(/__blankline;/g, '')
}

export default tsToJs
